import QtQuick 1.0
import Box2D 1.0

Rectangle {
	id: screen
	width: screenWidth; height: screenHeight


	function gravityChanged(xacc, yacc) {
		if(xacc > 5 || yacc > 5)
			world.gravity = Qt.point(xacc * 2, yacc * 2)
	}


	Slider{
		id: slider
		z: 100
		anchors.right: screen.right
		 /*linking to a signal in the Slider class instead of an
		 "onChanged" property alias because it doesn't work on
		 Maemo for some reason..*/
		onYChanged: {
			/*Scales the content of the world*/
			scaleRect.scale = ((sliderY / slider.height) - 1) * -1
		}


	}
	Image{
		id: background
		source: "qrc:///qml/images/background.png"
		anchors.fill: parent
	}

	Dynamite{
		id: dynamite
	}


	Flickable {
		id: flickable
		anchors.fill: parent
		contentWidth: world.width
		contentHeight: world.height
		boundsBehavior: Flickable.StopAtBounds
		flickableDirection: Flickable.HorizontalFlick




		Rectangle{
			property int origW: screen.width*3
			property int origH: screen.height*2

			id: scaleRect
			width: screen.width*3
			height: screen.height*2
			transformOrigin: Item.Bottom
			y: -screen.height //so the world is viewed from the floor
			color: "transparent"


			World {
				id: world
				width: parent.width
				height: parent.height

				gravity.x: 0
				gravity.y: -9.81

				MouseArea{
					id: dynamiteGen
					anchors.fill: parent
					onPressAndHold: {
						var object = dynamite.createObject(world)
						object.x = dynamiteGen.mouseX
                        object.y = dynamiteGen.mouseY
					}
				}

				Dam{
					id: dam
					anchors.horizontalCenter: parent.horizontalCenter
					anchors{
						bottom: pavement.top
					}
					floors: 7
					stairways: 7
				}

				Wall {
					id: pavement
					height: 10
					width: parent.width * 4 //so it fills screen when scaled
					anchors.horizontalCenter: parent.horizontalCenter
					image: "qrc:///qml/images/cement.png"
					anchors {
						bottom: ground.top
					}

				}

				Wall {
					id: ground
					height: 30
					width: parent.width * 4 //so it fills screen when scaled
					anchors.horizontalCenter: parent.horizontalCenter
					anchors {
						bottom: parent.bottom
					}

				}



			}//world
		}


	}



}
